package com.cqrcb.cloud.service.red.impl;

import com.cqrcb.cloud.entity.api.req.Q;
import com.cqrcb.cloud.entity.api.res.R;
import com.cqrcb.cloud.entity.exception.CustomException;
import com.cqrcb.cloud.entity.exception.ExceptionMember;
import com.cqrcb.cloud.entity.red.CustomerInfo;
import com.cqrcb.cloud.entity.red.RedEnvelopeCondition;
import com.cqrcb.cloud.entity.red.RedEnvelopeMain;
import com.cqrcb.cloud.entity.red.io.RedEnvelopeMainIO;
import com.cqrcb.cloud.mapper.red.CustomerInfoMapper;
import com.cqrcb.cloud.mapper.red.RedEnvelopeConditionMapper;
import com.cqrcb.cloud.mapper.red.RedEnvelopeMainMapper;
import com.cqrcb.cloud.service.red.RedEnvelopeConditionService;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* RedEnvelopeConditionImpl
*
* @author 系统
* @date 2021-10-29 04:55:32
*/
@Service
@Transactional(readOnly = true, rollbackFor = Exception.class)
public class RedEnvelopeConditionImpl implements RedEnvelopeConditionService {
    @Autowired
    private RedEnvelopeMainMapper redEnvelopeMainMapper;

    @Autowired
    private CustomerInfoMapper customerInfoMapper;

    @Override
    public R receive(Q<RedEnvelopeMainIO> redEnvelopeMainIOQ) {
        RedEnvelopeMainIO redEnvelopeMainIO = redEnvelopeMainIOQ.getBody();
        //首先去获取活动 判断活动有效期以及活动的条件，然后获取客户额度、然后判断客户是否满足活动的条件
        RedEnvelopeMain redEnvelopeCondition = redEnvelopeMainMapper.selectByPrimaryKey(redEnvelopeMainIO.getActId());
        if(redEnvelopeCondition == null){
            throw new CustomException(ExceptionMember.ACT_NOT_FIND);
        }
        if(redEnvelopeCondition.getStatus() == 0){
            throw new CustomException(ExceptionMember.ACT_INVALIDATION);
        }
        //条件
        String condition = redEnvelopeCondition.getCondition();


        CustomerInfo customerInfo = customerInfoMapper.selectByPrimaryKey(redEnvelopeMainIO.getCustomerId());

        return null;
    }


}
